Skip to content

fix(daemon): settle orphaned recording records when a recording starts - #4218

Merged
thymikee merged 5 commits into
callstack:mainfrom
sylvain-abadie:fix/finalize-orphaned-recording-after-device-restart
Nov 5, 2026
Merged

thymikee merged 5 commits into
callstack:mainfrom
sylvain-abadie:fix/finalize-orphaned-recording-after-device-restart

Conversation

@sylvain-abadie

@sylvain-abadie sylvain-abadie commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A device that restarts mid-recording can leave its screen recording record open/cleanup-pending with reason ownership-fence-lost. This happens when daemon recovery runs while the device is still booting: Android reports the manifest as missing while /sdcard is not mounted, and recovery then retains the record. Only daemon start and device-claim reconciliation retry it, and a recovered record stop cannot finish it because the recording died with the device. After the claim is gone, every record start on that device fails with cleanup-unconfirmed.

The start preflight now lists the records it refuses on, and record start settles the ones on its own device whose session the daemon no longer holds:

  • The settle does what the record's own stop would. It finishes the record with finishRecoveredDurableCapture, so a video that can still be exported (an iOS simulator recording whose daemon died) lands at its output path, and a later record stop in that session returns it. Only a record that cannot finish, such as the Android reboot case, falls back to the existing exact-owner recovery.
  • A record on another device is never recovered through the start device. A record that another device left under the start's own session name still refuses. The refusal names that device: stop it in that session, or start under another session name.
  • A record whose session the daemon still holds is never touched, so a failed record stop keeps its retry.
  • If the record cannot be confirmed cleaned, the start still refuses with cleanup-unconfirmed, and the refusal names the session.

The retry sits at record start, not in device-claim reconciliation: claim reconciliation settles only the claim's own session, and Android screen recording is the only capture kind with a device-side manifest that can misread during boot.

Commits: d9ef23d18 adds the start-time settle. b18cb9fed keeps it on the start device. 570661e62 finishes a record before cleaning it. c254f79c9 says in the help that the fallback recovery discards what the recording left. 2482c01a9 lets the settle and the refusal read one onStartDevice flag from the conflict list.

Validation

Tested SHA: 2482c01. pnpm check:affected --run --head 2482c01a9 passed (format, lint, typecheck, layering, fallow, build, vitest-related, unit), exactCommit=true.

Tests in record-runtime-orphan-recovery.test.ts (8 cases):

  • An orphaned record that can still finish is finished, not force-cleaned, and the new start succeeds.
  • An orphaned record whose finish fails is force-cleaned, and the new start succeeds.
  • Reattach reports missing: the record ends completed and the start succeeds.
  • An orphan of another session on another device stays open and does not block the start.
  • An unheld record under the start's own session name on another device is not completed, reattach is not called, and the refusal names that device.
  • A record whose cleanup stays pending still refuses with cleanup-unconfirmed.
  • A held session's record is never touched, with its live recording and after its binding is gone (a failed record stop); the refusal names the session.

Live runs (commands and record states are in the review thread):

  • Android (Medium_Phone API 36 as A, Pixel_2 API 27 as B): the stuck record from a reboot refuses a start on B under its own session name and stays open. A start under another session name on B succeeds. A start on A settles the record to completed/cleaned and records normally.
  • iOS 18.3 simulators: a start on the same simulator exports the orphaned recording before it starts. A start on another simulator under the same session name refuses, and record stop in that session then exports the video.

Known limits: on Android the failed finish leaves an unplayable <out>.collected.mp4 next to the old output path, as a failed record stop does today. Not covered: a physical iOS device, and two concurrent record start requests on one device.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

@sylvain-abadie is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@sylvain-abadie
sylvain-abadie marked this pull request as ready for review November 4, 2026 16:28
@thymikee

thymikee commented Nov 4, 2026

Copy link
Copy Markdown
Member

At edfa596, the code has no blocking problem, but the live Android evidence is missing. The PR body describes the emulator run in prose only. Please paste the record start, record stop and close commands with their output for the stuck state, the emulator id, the daemon version or SHA you ran, and the record file lifecycle and phase before and after.

Could a smaller design work? Keep refusing, but make cleanup-unconfirmed carry the blocking record's session address and the hint record stop --session <address>, which the existing stop-recovery lane already settles. If automatic settle is wanted, could the screen-recording start preflight return the conflicting unheld records, and settle them with one shared recovery-control helper that finishRecovered also uses? Then the selection cannot drift from the refusal. That would first need sessionsDir (or a "list blocking records" call) exposed from SessionStore instead of two dirname calls.

Not blocking, and fine to take or leave: (1) The settle at record-runtime-orphan-recovery.ts#L26 picks same-device unheld records, while the refusal fires for any non-completed record with this session path or this device. An orphan under the same session name on another device is still refused, and a user who runs open under the old name still gets cleanup-unconfirmed with no hint that record stop clears it. Deriving the settle set from the refusal's own predicate would fix both. (2) The acquireControl closure at line 32 nearly copies the one in finishRecovered (record-runtime.ts:518-529), so one shared helper could serve both. (3) The tests at line 36 all use reattachActive: true. A case where reattach returns missing and the record ends completed, and one where an orphan on a different device stays open, would cover the reported state. (4) The help sentence at index.ts#L130 sits in the Android paragraph, but the behavior applies on any platform. It could also name record stop --session <name> as the retry for a record that start cannot settle.

The only failing check is the Vercel deployment authorization, which is not a code problem. No conflicts are known.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

A device that restarts mid-recording can leave its screen recording
record open with a pending cleanup when the daemon's own recovery ran
while the device was still booting. Only daemon start and a device
claim reconciliation retried it, and a recovered record stop cannot
finish it without a playable artifact, so once the claim was gone
every later record start on that device was refused with
cleanup-unconfirmed.

The start preflight now lists the records it refuses on, and record
start runs the exact-owner recovery for the ones whose session the
daemon no longer holds, so the settle set cannot drift from the
refusal. A recovered stop and this settle share one recovery-control
helper. A record whose cleanup cannot be confirmed, or whose session
is still held, still refuses the start, and the refusal names that
session.
@sylvain-abadie
sylvain-abadie force-pushed the fix/finalize-orphaned-recording-after-device-restart branch from edfa596 to d9ef23d Compare November 4, 2026 18:35
@sylvain-abadie

Copy link
Copy Markdown
Contributor Author

Thanks. I tried the hint-only design first: in this state, record stop --session <old> fails (failed to retrieve playable Android recording) and the record stays open, so I kept the automatic settle in the shape you suggested. Updated to d9ef23d18.

  • The preflight lists the records it refuses on; the settle uses that list, skipping sessions the daemon still holds. No dirname in the daemon.
  • finishRecovered and the settle share exactRecoveryControl.
  • cleanup-unconfirmed names the blocking session.
  • Added the missing-reattach and other-device tests; moved the help sentence out of the Android text.
  • Not changed: a record under the current, held session's own name still refuses. The envelope has no session-lifetime marker, so it can't be told apart from this lifetime's failed stop.

Evidence: host macOS 26.7.1. Android emulator emulator-5556 (AVD Medium_Phone, Android 16, API 36). Baseline: npm agent-device@0.21.36. Fix: this branch at d9ef23d18 (0.21.37-dev). Private --state-dir, the same one for both daemons. Fault: adb reboot mid-recording, then agent-device daemon stop while the device boots, then the run's own device claim removed (the lease that owned r1 ended).

# 0.21.36
$ agent-device open com.android.settings --platform android --serial emulator-5556 --session r1   -> ok
$ agent-device record start <run>/r1.mp4 --scope device --session r1                                -> ok
# adb reboot; daemon stop while booting; device fully back; claim for r1 dropped
  record r1: lifecycle open, phase cleanup-pending, cleanupStatus cleanup-pending, reason ownership-fence-lost
$ agent-device record stop --session r1    -> FAIL UNKNOWN: failed to retrieve playable Android recording
  record r1: lifecycle open, phase completing, cleanupStatus cleanup-pending, reason ownership-fence-lost
$ agent-device record stop --session r1    -> FAIL UNKNOWN: failed to retrieve playable Android recording
  record r1: lifecycle open, phase completing, cleanupStatus cleanup-pending, reason ownership-fence-lost
$ agent-device close --session r1          -> FAIL SESSION_NOT_FOUND named_session_not_found
$ agent-device open com.android.settings --platform android --serial emulator-5556 --session r2   -> ok
$ agent-device record start <run>/r2-baseline.mp4 --scope device --session r2
                                           -> FAIL COMMAND_FAILED cleanup-unconfirmed
$ agent-device close --session r2          -> ok
  record r1: lifecycle open, phase completing, cleanupStatus cleanup-pending, reason ownership-fence-lost

# d9ef23d18, same state dir
$ agent-device open com.android.settings --platform android --serial emulator-5556 --session r2   -> ok
$ agent-device record start <run>/r2.mp4 --scope device --session r2                                -> ok
  record r1: lifecycle completed, phase completed, cleanupStatus cleaned
  record r2: lifecycle open, phase active
$ agent-device record stop --session r2    -> ok
$ agent-device close --session r2          -> ok
  record r1: lifecycle completed, phase completed, cleanupStatus cleaned
  record r2: lifecycle completed, phase completed

The record lines read lifecycle, metadata.phase, metadata.cleanupStatus and metadata.cleanupPendingReason from each screen-recording.resource.json.

pnpm check:affected --run --head d9ef23d18 passed.

@thymikee

thymikee commented Nov 4, 2026

Copy link
Copy Markdown
Member

At d9ef23d, the settle follows the refusal set and shares one recovery helper, and the live Android output covers the earlier request. One problem remains: the start-time settle can bind the wrong device and lose a live recording's only record. All checks pass.

The refusal set, and so the settle set, also holds a non-completed record at the start's own resourcePath on a different device (record-runtime.ts#L268). Take a record-only start such as record start --scope device --serial B --session r1, where r1's orphan record names device A. holdsSession is false for that record, so the settle calls exactRecoveryControl(params, session.device, false). That binds device B with record A's owner and fence. On the Apple runner path, inspectRunner(device, runnerSessionId) (recovery.ts#L347) then answers missing on B. Recovery marks record A completed with already-missing, and the new start on B overwrites it. On Android, the wrong-device read fails as ownership-fence-lost and the record stays, so the start still refuses there. Before this PR, the start refused. Now an iOS recording that may still run on device A can lose its only durable record, and nothing can stop or clean it. From reading the code, I have not confirmed whether gateway.bind refuses a device that differs from the owner's for every owner kind. A refusing bind would turn this into a retained record.

The rule to satisfy: exact-owner recovery binds the device the record names, never the requester's device. acquireExactDurableCaptureRecoveryControl in capture-kit already does this through deviceFromDurableResourceEnvelope (durable-capture-runtime-recovery.ts#L7); can the settle reuse it? A smaller option is to settle only records whose envelope.device matches the start device, and let a same-path record on another device refuse with its session named. Please add a test where an unheld record under the start's own session name sits on another device, and assert that it is not completed.

None of the open inline threads still applies: the record-runtime-orphan-recovery.ts thread is outdated because the file is deleted, and finishRecovered and the settle now share exactRecoveryControl. The other-device test thread is fixed by the 'leaves an orphaned record on another device open' test, though that test covers another session on another device, not the same-path case above.

A start refuses on a non-completed record at its own session path even
when that record names another device. The settle recovered that
record through the start device, so a recording still running on the
other device could have its only record completed from the wrong one.

The settle now recovers only records on the start device. A record
that another device left under the same session name still refuses,
and the refusal names that device: stop it in that session, or start
under another session name.
The start-time settle ran exact-owner recovery, which force-cleans any
capture it can reattach. On an iOS simulator that discarded a video a
record stop in the old session could still export, so a new start on
the same simulator lost the earlier recording.

The settle now does what the record's own stop would: it finishes the
record, so the export lands at its output path and a later record stop
in that session returns it. Only a record that cannot finish, such as
an Android recording whose device restarted, falls back to exact-owner
recovery.
@sylvain-abadie

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed and fixed. Updated to 570661e62 (two new commits on top of d9ef23d18).

To your open question first: gateway.bind does not refuse a device that differs from the owner's. RuntimeOwnerRef is local-family { family } or provider-runtime { provider, instance }, so it carries no device identity, and bindExactDevice does not compare devices. On iOS simulators the wrong-device bind went through: a start on simulator B replaced simulator A's record (log below).

  • b18cb9fed: the settle recovers only records on the start device, the smaller option you suggested. A record that another device left under the start's own session name still refuses with cleanup-unconfirmed. The message says "for this session", and the hint names that device: stop it in that session, or start under another session name. Added the test you asked for: an unheld record under the start's session name on another device is not completed, and reattach is not called.
  • 570661e62: while testing on iOS simulators I found that the settle discarded a video record stop could still export. Apple reattach maps a recorder that is gone but whose file can still be exported (restore-export) to active, and recovery force-cleans every active handle. That happened on the right simulator too. The settle now does what the record's own stop would: it calls finishRecoveredDurableCapture, and it runs exact-owner recovery only if that finish throws. On iOS the old export lands at its output path, and a later record stop --session r1 returns it. The Android reboot case still lands in recovery, because its finish fails.
  • I did not add a device guard to exactRecoveryControl. Both callers already prove the device: the stop path through assertManifestBelongsToRequest, the settle through the new filter. So the guard would be unreachable.

Known limits:

  • Android: the failed finish leaves an unplayable <out>.collected.mp4 (no moov atom) next to the old recording's output path. A failed record stop leaves the same file today. After the settle completes the record, nothing retries or removes it.
  • Not run: a physical iOS device (the inspectRunner path you cited), and two concurrent record start requests on one device.

pnpm check:affected --run --head 570661e62 passed (format, lint, typecheck, layering, fallow, build, vitest-related, unit), with exactCommit=true. Unit: record-runtime-orphan-recovery.test.ts has 8 cases. Removing the finish step fails 1 of them, and removing the recovery fallback fails 3.

Evidence

Host macOS 26.7.1. Android emulators: emulator-5556 (AVD Medium_Phone, API 36) as device A, emulator-5558 (AVD Pixel_2, API 27) as device B. iOS 18.3 simulators: iPhone 16 Pro 484762AD-97DC-4F45-B18D-C93CD26641CD as A, iPhone 16 Plus 65C965BA-C524-4BC4-9A9C-007784FCB620 as B (simctl backend). Every run used its own private --state-dir, and every daemon was built from this branch.

Android fault: adb reboot mid-recording, agent-device daemon stop while the device boots, then the run's own device claim removed. iOS fault: kill -9 of the run's own daemon, then the run's own device claim removed. The next daemon start kills the orphaned simctl recordVideo, but its file stays.

The record lines read lifecycle, fence.generation, the device id, metadata.phase, metadata.cleanupStatus and metadata.cleanupPendingReason from each screen-recording.resource.json.

1. iOS, before this update (d9ef23d18): the wrong-device bind on simulators

$ agent-device open com.apple.Preferences --platform ios --udid 484762AD-… --session r1   -> ok
$ agent-device record start <run>/r1.mp4 --scope device --session r1                     -> ok
  record r1 open gen 1 device 484762AD active
# kill -9 daemon; claim for r1 dropped
$ agent-device record start <run>/r1-on-b.mp4 --scope device --platform ios --udid 65C965BA-… --session r1   -> ok
  record r1 open gen 2 device 65C965BA active
# files: r1.native.mp4 (51678 B), no r1.mp4; simulator A's record was replaced

The same run with the start on simulator A itself (--session r1 --udid 484762AD-…) also settled gen 1 without an export: no r1.mp4, and r1.native.mp4 was left orphaned. In a third run, record stop --session r1 after the same fault exported r1.mp4 (46738 B). That is the loss 570661e62 fixes.

2. Android, at 570661e62: cross-device, the hint's workaround, and the original bug

$ agent-device open com.android.settings --platform android --serial emulator-5556 --session r1   -> ok
$ agent-device record start <run>/r1.mp4 --scope device --session r1                                -> ok
# adb reboot; daemon stop while booting; device fully back; claim for r1 dropped
  record r1 open gen 1 cleanup-pending cleanup-pending ownership-fence-lost
$ agent-device record start <run>/r1-on-b.mp4 --scope device --platform android --serial emulator-5558 --session r1
  -> FAIL COMMAND_FAILED cleanup-unconfirmed: A screen recording resource for this session has not reached a confirmed terminal state
     hint: The open screen recording record of session "r1" is on device "emulator-5556". Stop it in that session, or start this one under another session name.
  record r1 open gen 1 cleanup-pending cleanup-pending ownership-fence-lost
$ agent-device record start <run>/r2-on-b.mp4 --scope device --platform android --serial emulator-5558 --session r2   -> ok
  record r1 open gen 1 cleanup-pending cleanup-pending ownership-fence-lost
  record r2 open gen 1 active
$ agent-device record stop --session r2    -> ok
  record r2 completed gen 1 completed
$ agent-device record start <run>/r3-on-a.mp4 --scope device --platform android --serial emulator-5556 --session r3   -> ok (3 s)
  record r1 completed gen 1 completed cleaned ownership-fence-lost
  record r3 open gen 1 active
$ agent-device record stop --session r3    -> ok
  record r3 completed gen 1 completed
# files: r2-on-b.mp4 (54874 B), r3-on-a.mp4 (65850 B), r1.collected.mp4 (90373 B, unplayable: no moov atom)

3. iOS, at 570661e62: same simulator, the old export is kept

$ agent-device open com.apple.Preferences --platform ios --udid 484762AD-… --session r1   -> ok
$ agent-device record start <run>/r1.mp4 --scope device --session r1                     -> ok
  record r1 open gen 1 device 484762AD active
# kill -9 daemon; claim for r1 dropped
$ agent-device record start <run>/r2-on-a.mp4 --scope device --platform ios --udid 484762AD-… --session r2   -> ok (4 s)
  record r1 completed gen 1 device 484762AD completed
  record r2 open gen 1 device 484762AD active
# files: r1.mp4 (46805 B)
$ agent-device record stop --session r2    -> ok
$ agent-device record stop --session r1    -> ok, outPath <run>/r1.mp4 (the stored export)

4. iOS, at b18cb9fed (this path is unchanged by 570661e62): cross-simulator refusal, then the hint

# r1 recorded on simulator A; kill -9 daemon; claim for r1 dropped
$ agent-device record start <run>/r1-on-b.mp4 --scope device --platform ios --udid 65C965BA-… --session r1
  -> FAIL COMMAND_FAILED cleanup-unconfirmed
     hint: The open screen recording record of session "r1" is on device "484762AD-97DC-4F45-B18D-C93CD26641CD". Stop it in that session, or start this one under another session name.
  record r1 open gen 1 device 484762AD active
$ agent-device record stop --session r1    -> ok
  record r1 completed gen 1 device 484762AD completed
# files: r1.mp4 (46718 B)
$ agent-device record start <run>/r1-on-b.mp4 --scope device --platform ios --udid 65C965BA-… --session r1   -> ok
  record r1 open gen 2 device 65C965BA active
$ agent-device record stop --session r1    -> ok

Also at b18cb9fed: with r1 orphaned on simulator A, record start --session r2 on simulator B started, and r1 stayed open on A.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/capture-kit/src/capture-admission/durable-capture-start-preflight.ts">

<violation number="1" location="packages/capture-kit/src/capture-admission/durable-capture-start-preflight.ts:83">
P3: `otherDevice` is decided by the full identity key, but the hint prints only `device.id`. When the id matches and only the shape differs, the message names the start device itself as the other device. Decide the other-device case by id so the wording matches the printed id.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment on lines +83 to +86
const otherDevice =
deviceIdentityKey(conflict.envelope.device) === deviceIdentityKey(deviceIdentity(device))
? undefined
: conflict.envelope.device.id;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: otherDevice is decided by the full identity key, but the hint prints only device.id. When the id matches and only the shape differs, the message names the start device itself as the other device. Decide the other-device case by id so the wording matches the printed id.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/capture-kit/src/capture-admission/durable-capture-start-preflight.ts, line 83:

<comment>`otherDevice` is decided by the full identity key, but the hint prints only `device.id`. When the id matches and only the shape differs, the message names the start device itself as the other device. Decide the other-device case by id so the wording matches the printed id.</comment>

<file context>
@@ -80,13 +80,19 @@ function assertNoConflictingManifest<K extends string, C>(
   const [conflict] = listDurableCaptureStartConflicts(definition, resourcePath, device).records;
   if (!conflict) return;
   const session = conflict.envelope.sessionId;
+  const otherDevice =
+    deviceIdentityKey(conflict.envelope.device) === deviceIdentityKey(deviceIdentity(device))
+      ? undefined
</file context>
Suggested change
const otherDevice =
deviceIdentityKey(conflict.envelope.device) === deviceIdentityKey(deviceIdentity(device))
? undefined
: conflict.envelope.device.id;
const otherDevice =
conflict.envelope.device.id === device.id ? undefined : conflict.envelope.device.id;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. The settle skips a record by the same full identity key (deviceIdentityKey), so the refusal decides "other device" by that rule too. If the hint compared only ids, a record the settle skipped, with the same id but a different shape, would get the "for this device" wording, although the start never tried to settle it. The message stays tied to what the start actually did.

The record start help and the changeset described the fallback for a
record that cannot finish only as the exact-owner recovery a daemon
restart runs. Say that this recovery discards what the recording
left, so a caller knows a start can delete an unfinished recording.
@thymikee

thymikee commented Nov 5, 2026

Copy link
Copy Markdown
Member

At c254f79, the help-text problem from the earlier review (#4218 (comment)) is fixed: the help and changeset now say the start-time fallback discards what an unfinishable recording left. I found no new code problems, the one check is green, and there are no conflicts. I read the change and did not run it; the Android and iOS simulator transcripts are yours and predate c254f79, which changes only help text and the changeset.

One design question before this is ready: could listDurableCaptureStartConflicts decide device membership once and return { resourcePath, envelope, onStartDevice }? Today it already decides whether each conflict is on the start device and then drops that fact, so the settle and the refusal wording each recompute deviceIdentityKey(deviceIdentity(device)). With the tag, the settle would take records where onStartDevice && !holdsSession(sessionId), the refusal would pick "this device" or "another device" from the same field, and the two could not drift apart. If you prefer the current shape, a short note on why would settle it. The finish-then-recover order already looks like the smallest composition of the existing owners.

Not blocking, take or leave: the help still ends with "only closing the session disposes them", which holds only while the daemon holds that session; the hand-written identity comparisons could use sameDeviceIdentity from @agent-device/kernel/device, as screen-recording-stop-recovery.ts does; and when the ids are equal, the "other device" hint could print the shape that differs (the P3 wording thread; the id-only comparison it suggests is wrong, as your reply says). The other open threads are fixed or no longer apply at this head and can be resolved.

listDurableCaptureStartConflicts already decided whether each record
is on the start device, then dropped that fact, so the start-time
settle and the refusal wording each compared device identities again.
Return onStartDevice with each record and read it in both places, so
what the settle skips and what the refusal calls another device can
not drift apart. Compare with sameDeviceIdentity.

The record help said only closing the session disposes what a failed
record stop keeps. That holds only while the daemon holds the session;
once it does not, the next record start on that device settles it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sylvain-abadie

Copy link
Copy Markdown
Contributor Author

Thanks. Took the tag, updated to 2482c01a9.

  • listDurableCaptureStartConflicts now returns { resourcePath, envelope, onStartDevice }. The settle takes records where onStartDevice && !holdsSession(sessionId), and the refusal picks "this device" or another device from the same field. Neither recomputes the device identity anymore.
  • Both comparisons use sameDeviceIdentity.
  • The help now says: "while this daemon holds that session, only closing it disposes them, and once it does not, the next record start on that device settles them as described above."
  • I left the "other device" hint printing only the id. A different shape under the same id would need an Android serial and an Apple UDID (or two kinds) to collide, and printing the shape adds a formatter and a test for a hint that would not appear in practice. I can add it if you want it.

This is a refactor with no behavior change, so I did not rerun the devices. The existing tests pin both reads of the flag: if the settle ignores onStartDevice, 1 of the 8 cases in record-runtime-orphan-recovery.test.ts fails; if the flag is always true, 2 fail.

pnpm check:affected --run --head 2482c01a9 passed (format, lint, typecheck, layering, fallow, build, vitest-related, unit), with exactCommit=true.

@thymikee

thymikee commented Nov 5, 2026

Copy link
Copy Markdown
Member

At 2482c01, the code looks good, and the design question from the earlier review is settled. listDurableCaptureStartConflicts now tags each conflict with onStartDevice, the settle and the refusal wording both read that tag, and both comparisons use sameDeviceIdentity. Orphan recovery runs only for records on the start device whose session this daemon no longer holds, so a failed stop in a held session keeps its retry, and the held-session test pins it. The help text now scopes "only closing disposes them" to a held session.

The one reported check is green and there are no conflicts. I read the change and did not run it; the refactor looks behavior-neutral, and the Android and iOS simulator runs in the PR body cover the earlier heads.

Keeping the "other device" hint as the id only is fine, since the record stays refused either way (P3 thread). The other open threads are fixed or no longer apply at this head and can be resolved.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 5, 2026
@sylvain-abadie

Copy link
Copy Markdown
Contributor Author

The Coverage failure at 2482c01a9 does not seem related to this PR.

@thymikee
thymikee merged commit 22bd671 into callstack:main Nov 5, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants